#!/bin/bash

echo "启动图生图转接API服务..."

# 检查Python是否安装
if ! command -v python3 &> /dev/null; then
    echo "错误: 未找到Python3，请先安装Python 3.8+"
    exit 1
fi

# 检查.env文件是否存在
if [ ! -f .env ]; then
    echo "警告: .env文件不存在，请复制.env.example为.env并配置API密钥"
    echo "正在复制.env.example为.env..."
    cp .env.example .env
    echo "请编辑.env文件，填入您的Gemini API密钥后重新运行此脚本"
    exit 1
fi

# 检查是否已创建虚拟环境
if [ ! -d "venv" ]; then
    echo "创建虚拟环境..."
    python3 -m venv venv
fi

# 激活虚拟环境
source venv/bin/activate

# 安装依赖
echo "安装依赖包..."
pip install -r requirements.txt

# 创建上传目录
mkdir -p uploads

# 启动服务
echo ""
echo "========================================"
echo "图生图转接API服务启动中..."
echo "服务地址: http://localhost:5000"
echo "API文档: http://localhost:5000/api/v1/docs"
echo "健康检查: http://localhost:5000/health"
echo "前端示例: example_client.html"
echo "========================================"
echo ""
echo "按 Ctrl+C 停止服务"
echo ""

python3 run.py
